home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 237
/
237.d81
/
t.making mazes
< prev
next >
Wrap
Text File
|
2022-08-26
|
3KB
|
122 lines
u
M A Z E M A N
by Victor Terrana, Ph.D.
For the purpose of explaining the
algorithm we should consider the
screen to be covered by a rectangular
grid. We will use coordinates to
number the points in the grid
starting with (1,1) in the upper left
hand corner. The diagonal lines
which form the walls and passages of
the maze connect opposite corners of
the squares of our grid. The points
in the grid may be thought of as
having even or odd parity according
to the value of the sum of the two
coordinates of that point.
(1,1) (1,2) (1,3) (1,4)
. . . .
(2,1) (2,2) (2,3) (2,4)
. . . .
(3,1) (3,2) (3,3) (3,4)
. . . .
The important fact here, and the
secret to the construction of the
maze is that the diagonal lines
always connect points of the same
parity, either odd to odd or even to
even. For instance, the point (2,3)
can be connected only to the four
points (1,2), (1,4), (3,2) or (3,4).
All of these points have the same
(odd) parity.
This principle of mathematical
parity allows for a very simple
method of maze construction. We can
form two (necessarily separate) wall
sections, one connecting only points
of odd parity and the other
connecting only those with even
parity. We position these two wall
segments leaving spaces between the
pairs of end points to act as the
entrance and exit to the maze.
The area confined by these two
walls may now be filled at random with
diagonal lines (and a few blank
spaces). It is impossible to cut off
the entrance from the exit since this
would involve a connection between one
wall and the other consisting of
diagonal lines. But these lines can
never connect a point of odd parity
(from one wall) with a point of even
parity (from the other wall)! Thus, no
matter how the interior of the maze is
filled in with diagonal lines (between
points in our grid) there will always
be at least one path between the
beginning and the end of the maze.
The proportion of blank spaces
used in the maze determines, to an
extent, its complexity. If no spaces
are used, the maze will consist of a
single, long (but not very
challenging) path from the entrance
to the exit. Use of a few spaces
allows for a choice of paths.
However, many of these lead the maze
tracer on a long journey back to
where he/she started. The use of too
many spaces creates several paths
from entrance to exit and again may
lead to a rather easy maze. The
mazes formed by this program have
about 5% blank spaces, a proportion
which leads to fairly complex mazes
without too many paths from beginning
to end.
Those readers who wish to try
using the algorithm explained here in
their own programs might want to
consider a couple of alterations.
The border of the maze can be made
almost any shape as long as it
consists of two pieces with opposite
parity. You could create customized
mazes using a special set of shapes.
More traditional horizontal-
vertical mazes can be constructed by
using line segments two units long
connecting either points with two even
coordinates to each other or those
with two odd coordinates. The
remaining points in the grid become
midpoints of these segments. In any
case, Jeff and I both hope you enjoy
the program we created from my
algorithm. Have fun!
Vic Terrana